<template>
  <div class="add_financing_config_page">
    <div class="mod">
      <div class="title">
        <i class="icon"></i>
        <h5 class="name">融资参数信息</h5>
      </div>
      <el-form ref="form" :model="form" :rules="rules" label-position="right">
        <el-row class="row">
          <el-col :span="12">
            <el-form-item label="编号" prop="code" label-width="180px">
              <el-input v-model="form.code" placeholder="系统自动生成" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="金融机构产品名称" prop="projectName" label-width="180px">
              <el-input v-model="form.projectName" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="row">
          <el-col :span="12">
            <el-form-item label="金融机构名称" prop="jigouName" label-width="180px">
              <el-input v-model="form.jigouName" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="核心企业名称" prop="hexinName" label-width="180px">
              <el-input v-model="form.hexinName" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="row">
          <el-col :span="12">
            <el-form-item label="担保费利率（%）" prop="guaranteeRate" label-width="180px">
              <el-input v-model="form.guaranteeRate" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="融资利率（%）" prop="financingRate" label-width="180px">
              <el-input v-model="form.financingRate" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="row">
          <el-col :span="12">
            <el-form-item label="罚息利率（%）" prop="punishRate" label-width="180px">
              <el-input v-model="form.punishRate" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="服务费利率（%）" prop="serviceRate" label-width="180px">
              <el-input v-model="form.serviceRate" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="row">
          <el-col :span="12">
            <el-form-item label="状态" prop="status" label-width="180px">
              <el-select v-model="form.status" style="width: 100%;">
                <el-option
                  v-for="item in statusList"
                  :key="item.label"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="mod">
      <div class="btns">
        <el-button class="btn btn_cancel" @click="$router.back()">取 消</el-button>
        <el-button class="btn" type="primary" @click="submit">提 交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { financingConfigDetail, addFinancingConfig, editFinancingConfig } from '@/api/argumentConfig'

export default {
  data() {
    return {
      statusList: [ // 状态列表: '0': 启用; '1': 禁止;
        {
          label: '启用',
          value: '0',
        },
        {
          label: '禁止',
          value: '1',
        }
      ],
      form: {
        code: '', // 编号
        jigouName: '', // 金融机构名称
        projectName: '', // 金融机构产品名称
        hexinName: '', // 核心企业名称
        guaranteeRate: '', // 担保费利率（%）
        financingRate: '', // 融资利率（%）
        punishRate: '', // 罚息利率（%）
        serviceRate: '', // 服务费利率（%）
        status: '', // 0 启用 1 禁止
      },
      rules: {
        // code: [{ required: true, trigger: ['change', 'blur'], message: '' }], // 编号
        jigouName: [{ required: true, trigger: ['change', 'blur'], message: '请输入金融机构名称' }], // 金融机构名称
        projectName: [{ required: true, trigger: ['change', 'blur'], message: '请输入金融机构产品名称' }], // 金融机构产品名称
        hexinName: [{ required: true, trigger: ['change', 'blur'], message: '请输入核心企业名称' }], // 核心企业名称
        guaranteeRate: [{ required: true, trigger: ['change', 'blur'], message: '请输入担保费利率' }], // 担保费利率（%）
        financingRate: [{ required: true, trigger: ['change', 'blur'], message: '请输入融资利率' }], // 融资利率（%）
        punishRate: [{ required: true, trigger: ['change', 'blur'], message: '请输入罚息利率' }], // 罚息利率（%）
        serviceRate: [{ required: true, trigger: ['change', 'blur'], message: '请输入服务费利率' }], // 服务费利率（%）
        status: [{ required: true, trigger: ['change', 'blur'], message: '请选择状态' }], // 0 启用 1 禁止
      },
      id: '',
      detailObj: {},
    }
  },
  mounted() {
    if (this.$route.query.id) {
      this.id = this.$route.query.id
      this.getFinancingConfigDetail()
    }
  },
  methods: {
    getFinancingConfigDetail() {
      financingConfigDetail(this.id).then((res) => {
        Object.keys(this.form).forEach((key) => {
          this.form[key] = res.data[key]
        })
      })
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          let result
          if (this.id) {
            result = editFinancingConfig(this.form)
          } else {
            result = addFinancingConfig(this.form)
          }
          result.then((res) => {
            this.$message({
              type: 'success',
              message: res.msg || '提交成功',
              onClose: () => {
                this.$router.back()
              }
            })
          }).catch(() => {

          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/assets/styles/variables.scss';

.add_financing_config_page {
  .mod {
    background-color: #fff;
    box-shadow: 0 1px 2px 0 rgba(1, 24, 70, 0.09);
    border-radius: 6px;
    margin-bottom: 16px;
    padding: 20px 16px 24px;
    .title {
      color: #333;
      font-size: 16px;
      font-weight: 600;
      display: flex;
      align-items: center;
      margin-bottom: 20px;
      .icon {
        width: 3px;
        height: 16px;
        border-radius: 1px;
        background-color: $theme;
        margin-right: 5px;
      }
    }
    ::v-deep .el-form-item--medium .el-form-item__label {
      color: #777;
    }
    .btns {
      display: flex;
      justify-content: center;
      align-items: center;
      .btn {
        width: 120px;
      }
      .btn_cancel {
        margin-right: 24px;
      }
    }
  }
}
</style>
